﻿using System.Data;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.Text;
using Entities;

namespace Distribution.Data
{
    public class DVendor
    {
        #region - Public methods -
        
        public static List<EVendor> GetAll() 
        {
            SqlCeConnection _Con = null;
            StringBuilder query = new StringBuilder();

            try
            {
                _Con = Helper.GetConnection();

                query.Append("SELECT VendorId, Name ");
                query.Append("FROM tb_Vendor ");

                SqlCeCommand command = new SqlCeCommand(query.ToString(), _Con);
                command.CommandType = CommandType.Text;

                SqlCeDataReader dr = command.ExecuteReader();

                List<EVendor> vendors = new List<EVendor>();

                while (dr.Read())
                {
                    EVendor vendor = new EVendor();

                    vendor.Id = dr.GetInt32(dr.GetOrdinal("VendorId"));
                    vendor.Name = dr.GetString(dr.GetOrdinal("Name")); ;

                    vendors.Add(vendor);
                }

                return vendors;
            }
            finally
            {
                if (_Con != null)
                {
                    _Con.Close();
                }
            }
        }

        #endregion
    }
}
